package com.hcw.bankdemo.mapper;

import com.hcw.bankdemo.model.Account;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

/**
 * @ClassName AccountMapper
 * @description: 数据库操作层
 * @author: hcw
 * @time: 2020/8/29 10:35
 */
@Mapper
public interface AccountMapper {
    /**
     * @description: 根据账户名获取账户信息 带锁
     * @param :accountName
     * @return: Account
     * @author: hcw
     * @time: 2020/8/29 10:40
     */
    @Select("SELECT * FROM account WHERE accountName=#{accountName} for update")
    Account getAccountByNameLock(String accountName);

    /**
     * @description: 根据账户名获取账户信息 带锁
     * @param :accountName
     * @return: Account
     * @author: hcw
     * @time: 2020/8/29 10:40
     */
    @Select("SELECT * FROM account WHERE accountName=#{accountName}")
    Account getAccountByName(String accountName);
    /**
     * @description: 根据id更新用户余额
     * @param accountName,currentMoney
     * @return:
     * @author: hcw
     * @time: 2020/8/29 10:41
     */
    @Update("UPDATE account SET currentMoney=#{currentMoney} where accountName=#{accountName}")
    Integer updateAccountByAccountName(String accountName, BigDecimal currentMoney);
}